Programming-by-example using disjunctive programs

ABSTRACT

Systems, methods, and computer-executable instructions for synthesizing a program for a task. A domain specific language that includes a disjunctive symbol and an input/output example for the task are received. A program for the task is synthesized based on the input/output example and the domain specific language. Sub-programs for an instance of the disjunctive symbol are synthesized, A set of feature calculators and target feature values are determined. The program for the task is returned. The program includes the sub-programs, the set of feature calculators and the target feature values.

BACKGROUND

Many computer users and knowledge workers are not computer programmers, and yet commonly face challenges for which programming skills would be useful or needed. Example data manipulation tasks include extracting substrings of text from a column in a spreadsheet and extracting important data fields from a collection of richly formatted emails or web pages. Such tasks may be performed by professional programmers by writing custom extraction scripts using regular expressions, macros or CSS expressions. These solutions, however, require programming skills that a computer user may not have.

A program-by-example (PBE) system may be beneficial in helping end users to automate the generation of such scripts. A PBE system allows the user to specify their intent by providing one or more input-output examples of the desired task. From these input-output examples, a PBE system attempts to automatically generate a program in an underlying domain specific language (DSL) that satisfies the given examples. Instead of opaquely automating one-off tasks, PBE may produce lightweight scripts in common programming languages that may be saved and reused by users in different environments, independently of the learning techniques used to infer those scripts.

PBE approaches have seen significant interest and progress in recent years. One challenge faced by current PBE systems is that the programs inferred from a few examples generally lack robustness and easily fail on new inputs. This is because the state space of possible programs (defined by the DSL) is large, since the DSL needs to support expressive programs covering different tasks, and hence there can be many possible programs satisfying a given set of input-output examples provided by the user. This expressivity vs. correctness trade-off is a challenge in the design of PBE systems, which is why there has been a strong effort in the synthesis community to improve the ranking used in PBE systems to choose the most likely program the user may want out of the large set of candidates that logically satisfy the given examples.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a graph showing the number of examples needed for correct synthesis in accordance with respective examples.

FIG. 2 is a flow diagram of a process for synthesizing a disjunctive program in accordance with respective examples.

FIG. 3 is an example computing device that can be used in conjunction with the technologies described herein.

DETAILED DESCRIPTION

In current PBE systems, a ranking system is used during program synthesis to rank the different candidate programs created by the PBE system. The ranking system, therefore, allows a PBE system to select one of the candidate programs as the synthesized program to return to the user. As the ranking system is used during the synthesis of a program, the ranking system may only consider the one or more input-output examples provided by the user. Accordingly, the ranking system cannot use new input provided by after synthesis when the synthesized program is to be executed on some future input.

Further, no matter how good a ranking technique is, ranking during synthesis restricts the PBE system to choose a single option from a set of many likely possibilities. This is true for synthesis at every sub-program level, not just for final programs. Thus, each sub-program level provides an opportunity for a PBE system to choose a sub-program that may not be robust with new input.

In this disclosure, a PBE system is described that increases robustness of a final program and sub-programs by not prematurely committing to a single choice of program at synthesis time. Instead, the ranking decision is delayed to the execution of the program when there is more information available, i.e., new input on which the program is to be executed. The final program produced by the disclosed PBE system synthesizes a disjunctive program that includes many possible top-ranked programs as possible alternatives and selects between these different choices upon execution on the new input. This delayed choice brings the important benefit of comparing the possible outputs produced by the different disjuncts on a given input at execution time. Thus, the new ranking system considers the new input that was not available at synthesis time. A disjunctive program may also use different sub-programs/disjuncts based on different data to produce accurate output. Using the disclosed features, an increase from 59% to 93% of tasks for which correct programs were learned from a single example was achieved.

Table 1 shows an example data cleaning scenario where a user would like to remove the arbitrary description that occurs around the product ID in the input column, as shown in the desired output column. The user may provide the first row as the only input-output example. With this one example a PBE system based on regular expressions such as Flash Fill can generate many possible satisfying programs that employ different substring extraction logics.

TABLE 1 Input Desired output 12 units PID 24122 Laptop PID 24122 43 units PID 98311 Wireless keyboard PID 98311 7 units PID 21312 Memory card PID 21312 22 units PID 23342 Docking station v2 PID 23342 6 units PID 64232 Mouse with pad PID 64232 . . . . . .

For instance, a possible logic, as part of a synthesized program, to detect the end of the extracted substring could include “the end of the last number” (program 1 (P₁)), “the end of the second number” (P₂), “the end of the first number that occurs after capital letters and whitespace” (P₃), along with many other expressions that would properly extract the intended substring. Some current PBE systems favor simplicity, in which case the PBE system would select the program P₁. However, this program fails on row four, where there happens to be another number occurring at the end of the input, and so the program P1 would incorrectly output the string “PM 23342 Docking station v2” for row four. The programs P₂ or P₃, however, would have produced the correct result. The data in row four, however, was not available during program synthesis. Further, a user has no way of knowing which examples to provide to the PBE system to ensure that the PBE system learns better programs.

Improving the ranking system in current PBE systems to choose a better program has limits, because there is no single ranking strategy that will work in all cases. Depending on the variability in the data set, it is possible that there is no single logic that will satisfy all input. Rather, there may be different programs that apply to different rows to solve the overall task more correctly/robustly. For example, on an input row such as “22 units PID 23342 Docking station VERSION 2” the program P₃ would fail, or on a row “22 to 25 units PID 23342 Docking station v2” the program P₂ would fail. Hence, in such situations any one ranking scheme used to select one program would fail on some inputs.

Thus, the robustness of a synthesized program is negatively impacted by restricting logic/sub-programs to a choice of extraction logic at the synthesis stage. In this disclosure, rather than prematurely enforcing a single choice Pi from the list of top-ranked programs P1, . . . , Pn in the synthesis algorithm, the disclosed PBE system instead synthesizes a more robust disjunctive program that includes all of the choices P1, . . . , Pn and selects between these different logic/sub-programs/disjuncts when the final synthesized program is executed on a new input. Hence, with this disjunctive approach, the PBE system delays the choice of which logic/sub-program/disjuncts to use until the input is received at execution time. The PBE system may then compare the outputs produced by the different logics at one or more different levels on the input to select the logic/sub-program/disjunct.

Another example from the domain of web extraction is provided below. In this example, the user's extraction task is to extract a particular data field from a structured HTML document, such as extracting the flight number from an email containing a flight itinerary. In existing PBE systems for web extraction, the user may perform such a task by giving examples of the desired field on a few mails, from which the system will synthesize node selection expressions based on languages such as XPath or CSS selectors to extract nodes in the HTML DOM (Document Object Model). For example, assume the user example of the desired field refers to the following SPAN element node in the HTML markup: <span style=“color: gray” class=“c1”>BA052</span>

The challenge comes in choosing which properties of the example nodes to include or exclude in the node selection logic, as it is not known which of these properties would be varying in other inputs. For example, in this case possible selection logics include “color is gray” (P₁), “class is c1” (P₂) or the more restrictive conjunction of the two properties “color is gray and class is c1” (P₃). Some ranking schemes choose to be conservative and choose the most specific logics. These logics, however, tend to impose too many constraints and overfit the examples. These logics, therefore, fail to return any result on new inputs. Choosing more general logics has the pitfall of losing important properties and identifying incorrect nodes.

This is another example where using a disjunctive approach to maintain a set of these different possible selection logics in the synthesized program would be beneficial. The logic may then be selected at execution time when the new input is available. For example, the program may first try the most specific logic and if that fails to return any result then less restrictive logics may be tried.

The number of possible logics, however, may be too large to include all the possible logics in the final program. For example, in the above SPAN example the set of possible logics grows exponentially with the number of properties that a node may have, as possible conjunctions of the predicates correspond to all possible subsets. Including all these possibilities in a disjunctive program would not be viable, both in terms of performance of the learning algorithm as well as the size and execution time of the final synthesized program. Accordingly, in some embodiments, a technique is used to compute the maximal (the most specific) as well as a set of minimal (least restrictive)programs that satisfy the example extractions and together cover all the properties of the example nodes. These candidates covering all the observed properties may be chosen as effective disjuncts by the synthesis algorithm to yield efficient and robust disjunctive program.

The above two examples illustrate how PBE systems generate programs that may easily fail on new inputs. However, providing more examples to existing PBE system does not guarantee the PBE system will learn better programs. Even if users are willing to give many examples, the user cannot know which examples to give. Generally, provided examples are representative of their target data and used by the PBE system to learn a program. A program providing incorrect output is an especially important concern in situations where the user cannot recover from the problem by attempting to relearn a different program when the failure case is encountered. This may be because the failure may occur at any point in the future in a different execution environment (or for a different user of the program) where access to the learning system is no longer possible.

In the disclosed PBE systems, the top-program selection is moved from ranking in the synthesis phase to the semantics of the program itself. This may be achieved by maintaining multiple disjuncts in the final program. One challenge with maintaining multiple disjuncts in the final program is the technique for deciding which disjuncts to include, as well as the nature of the selection mechanism that decides between the disjuncts at execution time. In some embodiments, the choices are guided by the goals of correctness as well as performance of the synthesized programs. Described herein are concrete implementations of the disjunctive approach for the text and web application domains, as well as a generic framework in which arbitrary DSLs and synthesis algorithms may be extended to support the learning of disjunctive programs.

The design of a domain specific language (DSL) is an important requirement for any synthesis system. The DSL needs to strike a balance between expressiveness (to handle a range of common tasks in the target domain) and tractability (for the synthesis algorithm to learn correct programs efficiently).

A DSL is defined as a context-free grammar of the form ({tilde over (ψ)}_(N), {tilde over (ψ)}_(T), {tilde over (ψ)}_(st), {tilde over (ψ)}_(in)R), where {tilde over (ψ)}_(N) is a set of non-terminal symbols, {tilde over (ψ)}_(T) is the set of terminal symbols, {tilde over (ψ)}_(st) is the start symbol, {tilde over (ψ)}_(in) the input symbol and R is the set of production rules of the grammar. Each symbol ψ is semantically interpreted as ranging over a set of values [[ψ]], which may be standard programming types such as integers, strings, arrays, lambda expressions, etc. Each production rule r ∈ R represents an operator in the programming language, and is of the form ψ_(h):=Op(ψ₁, . . . , ω_(n)), where Op is the name of the operator, which takes parameter types given by the body symbols ψ_(i) ∈{tilde over (ψ)}_(N) ∪{tilde over (ψ)}_(T) and returns a value of type given by the head symbol ω_(h) ∈{tilde over (ψ)}_(N). Hence the formal semantics of the DSL, is given by an interpretation of each rule r as a function:

[[r]]:[[ψ ₁]]× . . . × [[ψ_(n)]]→[[ψ_(h)]]

where ψ_(h) is the head symbol and ψ₁ . . . ψ_(n) are the body symbols of the rule operator. A program P of type ψ is any concrete syntax tree defined by the DSL grammar with root symbol ψ. A complete program has the root symbol ψ_(st). Any derivation from a non-root symbol is a sub-program. The input symbol ψ_(in) is a terminal symbol that represents the input to the overall program, and is a global variable that is available to the semantics of all operators in the programming language.

Table 2 shows the DSL

for text manipulation, which is based on the Flash Fill language for string processing using regular expressions. The symbols of the grammar are shown with their associated semantic types with the start and input symbols explicitly marked. The input hip in this case is a string and the output of any complete program res is also a string, e.g., a substring of the input as in the extraction scenario in Table 1. At the top level, the output is a concatenation Concat of constant strings Const or some substrings of the input defined by sub. A substring expression Substr(p1,p2) extracts the substring between two positions p₁ and p₂ in the input string. Position expressions are defined as either constant positions Pos(k), or Pos(r₁, r₂, k) which determines the kth position in the input string whose left and right sides match regular expressions r₁ and r₂ respectively. For example, the program for the task in Table 1 that extracts the substring from the first capital letter to the last number is given as Substr(Pos(∈, Caps, 0). Pos(Num, ∈, −1)) (Substr 1) where the negative k indicates occurrence from the end of the string. An alternative program for the same task that extracts until the end of the second number rather than the last number is given as Substr(Pos(∈, Caps, 0), Pos(∈, Num, 1)) (Substr 2).

TABLE 2 @start string res := sub | Const(s) | Concat(res, res) string sub := Substr(p, {grave over ( )}p) int p := Pos(r, r, k) | Pos(k) Regexr := ∈ | t | ConcatReg(r, r) @input string inp int k string s Regex t

Table 3 shows the DSL

for extracting nodes from an HTML document.

is based on path expressions and filter predicates similar to CSS selectors. The input inp in this case is the DOM tree of the entire HTML document and the output n of any complete program is a particular node in this tree, e.g., the node containing the flight number in a flight itinerary, as in the extraction task described above.

The top level operator Select(fl, k) selects the kth node from a filtered collection of nodes fl in document order. The Filter(sel, c) operator filters all nodes in a selection sel using a condition c. The sel may be all the nodes in the document (All) or the children of any nodes obtained by another filter operation as given by Children(fl). The condition c used for filtering is a boolean function on nodes defined by a range of atomic predicates (constraints including tag type of the node, its ID, class, regular expression matches in the text content, number of children, style and attributes) as well as any conjunctions Conj(c, c) of these predicates.

For example, a program to extract the 3rd node in a document that has class “c1.” and is the child of a “TD” element is given as Select(Filter(Children(Filter(All( ), Tag(“ID”))), Class(“c1”)), 3).

TABLE 3 @start Node n := Select(fl, k) Node[ ] fl := Filter(sel, c) Node[ ] sel := All( ) | Children(fl) Func 

 Node,bool 

 c := Tag(s) | Class(s) | ID(s) | Text(r) | NthChild(k) | NumChild(k) | Style(s, s) | Attr(s, s) | Conj(c, c) @input DomTree inp string s int k Regex r

As described below, any DSL may be extended to support disjunctive programs. For example, the DSL designer may choose to provide disjunctive support for any symbols defined in their DSL. Table 4 illustrates a disjunctive extension to a text DSL to support disjunctive programs at the substring operator level. This is indicated by the @disj {f} annotation before the sub symbol. This annotation includes a reference to a new symbol f that has been added to the grammar, which defines a number of feature calculators in the DSL that are used to choose between different substring logics at execution time. The annotation @disj {f} indicates that a disjunctive subprogram for symbol sub is of the form:

Disj([P ₁ , . . . , P _(n) ], [F ₁ , . . . , F _(m) ], [v ₁ , . . . , v _(m)])

where [P₁. . . , P_(n)] is an array of disjuncts of type sub, [F₁, . . . F_(m)] is an array of feature programs of type f, and [v₁, . . . , v_(m)] is an array of objects of type obj. In an example, the disjunction operator Disj chooses between possible disjuncts P₁, . . . , P_(n) by computing a feature vector on the output of each P_(i) using the feature functions [F₁, . . . F_(m)], and then choosing the output that has a feature vector most similar to the target feature values [v₁, . . . , v_(m)].

TABLE 4 @disj{f} string sub := Substr(p, p) Func(string, obj) f :=NotNull( ) | NumChars( ) | NumNonWS( ) | SpecialChars( )

As an example, let us consider the following disjunctive program that addresses the task in Table 1:

Disj([P₁, P₂], [NotNull( ), NumChars( )], [True, 9])

where P₁ and P₂ correspond to the two Substr programs, Substr 1 and Substr 2, defined above. P₁ extracts up to the last number in the input while P₂ extracts up to the second number. In this example, the disjunctive program uses only two feature calculators: NotNull( ) which computes a boolean value indicating if the output substring is non-null, and NumChars( ) which computes the number of characters in the output substring. The target feature values expected for these two features are True and 9, since the output string should be non-null and the product ID strings are of length 9. Hence, when executing this disjunctive program on the inputs in Table 1, both disjuncts P₁ and P₂ will produce equally scoring outputs on the first three inputs, but on the fourth input P₂ produces the higher scoring output for the target feature vector. This is because P₂ will output the correct “PID 23342” while P1 will output “PID 23342 Docking station v2”. Accordingly, the feature calculator for P1 will not match the NumChars( ) output since the output is not nine characters.

A disjunctive program does need not use all the feature calculators available in the DSL as only some of them may be relevant to the particular situation. The above example program uses two of the calculators, though the DSL could support other features such as NumNonWS( ) and SpecialChars( ) which compute the number of non-whitespace characters and the set of special characters occurring in the output. The DSL may include various feature calculators, and the synthesis algorithm may then select which features and the target value vector to include in the disjunctive program based on the provided example(s).

Table 5 shows example of a disjunctive DSL that includes extensions made to a web DSL. As discussed above, finding a node within a DOM involves an uncertainty in what logic to use to filter nodes down to the target extraction. Due to this, support for disjunctive programs for the fl symbol is chosen in order to consider alternative filtering logics in the final program. In this example, a single feature calculator NonEmpty( ) that checks if the filtered set contains at least one node is used.

TABLE 5 @disj{f} Node[ ] fl := Filter(sel, c) Func(string, obj) f :=NonEmpty( )

As an example, the following disjunctive program addresses the flight number extraction task described above:

Disj([P₁, P₂, P₃], [NonEmpty( )], [True])

where

P₁=Filter(All( ), Conj(Style(“color”, “gray”), Class(“c1”)))

P₂=Filter(All( ), Class(“c1”))

P₃=Filter(All( ) Style(“color”, “gray”))

In this example, the most restrictive conditions may be tried first, and if the program fails to find any nodes then less restrictive conditions may be tried. This example also illustrates that the Disj( ) operator may use the ordering on the disjuncts to select the first disjunct if there are ties in the feature scores for different disjuncts.

Although the above sample DSLs for both the text and web domains have disjunctive support for only one symbol in each DSL, a DSL may include any number of disjunctive symbols. One example of a DSL including disjunctive support for two different symbols is the language DSL

, which combines both grammars DSL

and DSL

along with a top-level operator that first extracts the node from an HTML document and then performs a substring extraction on the text content of this node.

The formal semantics of the Disj( ) operator and the formulation of disjunctive DSLs in an abstract framework is described below. A disjunctive DSL is of the form ({tilde over (ψ)}_(N), {tilde over (ψ)}_(T), {tilde over (ψ)}_(st), {tilde over (ψ)}_(in), R, Δ), which extends the definition of a standard DSL given above with the one additional parameter Δ. The parameter Δ: {tilde over (ψ)}_(N)→ψ_(f) maps certain symbols that support disjunctives to the symbols that represent their feature calculators. The well-formedness constraint on this map is that if Δ[ψ]=ω_(f) then the type of ψ_(f) is Func(ψ, obj). For example, the text DSL has Δ[sub]=f mapping the single substring symbol to its feature calculator symbol in the grammar.

Given tp that supports disjunctive with Δ[ψ]=ψ_(f), let T=[[ψ]] be the semantic type of ψ. The semantics of the disjunction operator for ψ is defined in Table 6 below. The operator takes as parameters the outputs produced by a list of disjuncts (disjuncts), the list of feature calculators to compute relevant features on these outputs (features), and the target vector v of values for each of the features (which, in an example, is expected to be of the same length as the features array).

TABLE 6 Disj (T[ ] disjuncts, Func(T, obj)[ ] features, obj[ ] v) { for each d in disjuncts let s = {i | features [i](d) == v[i]} let score [d] = s return the first d in disjuncts where score[d] = Max(score) }

The operator computes the given features on each of the disjunct outputs and returns the output on which the most feature values match the target values in v. In an example, this is the scoring function used to select the disjunct. In other examples, however, a different scoring function may be used to select between different disjuncts that may incorporate weights associated with different features or use more sophisticated similarity measures than simple equality of feature values. For example, one feature may be more heavily weighted compared to other features.

In addition, in some examples, only minimal thresholds of feature values may need to be satisfied to accept a disjunct, in which case not all disjunct outputs need to be computed. Rather, a more performant lazy evaluation in which the first disjunct that satisfies the given thresholds may be selected.

Using disjuncts may be incorporated into a PBE system. Accordingly, a synthesis algorithm may learn/synthesize disjunctive programs from input-output examples. The algorithm described is agnostic of any particular DSL, as the algorithm takes the DSL and some other domain-specific properties as configuration parameters for particular domain instantiations. An example algorithm is shown below in Table 7.

In an example, the algorithm is based on learning program expressions in the DSL by propagating example-based constraints on any expression to its subexpressions. The constraint propagation may be done using domain-specific properties of DSL operators, which may be provided in the configuration parameter.

TABLE 7  1: function SynthProg(C, ϕ, ψ)  2: let C.DSL = ({tilde over (ψ)}_(N), {tilde over (ψ)}_(T), {tilde over (ψ)}_(st), {tilde over (ψ)}_(in), R, Δ)  3: Progs ← ∅  4: if C.Synth[ψ] is defined for ψ then  5:  Progs ← C.Synth[ψ](ϕ)  6: else  7:  for each r ∈ R where r has head ψ do  8: let r be ψ := Op(ψ_(i) , . . . , ψ_(n))  9: S← {[ ]} 10: for i = 1 . . . n do 11: S′ ← ∅ 12: for each [P₁, ... P_(i−1)] ∈ S do 13: ϕ_(i) ← C.InferSpec[r ](ϕ, ψ_(i),[P₁, ..., P_(i−1)]) 14: {tilde over (P)} ← SynthProg(C.DSL, ϕ_(i), ψ_(i)) 15: S′ ← S′ ∪ {[P₁, ... , P_(i−1),P] | P ∈ {tilde over (P)}} 16: S ← S′ 17: Progs ← {Op(P1 , ..., Pn) | [P1 , ..., Pn] ∈ S} 18:  topProgs C.Ranker(Progs ) 19:  if Δ[ ψ] not defined then 20: return topProgs 21:  else 22: ψ_(f) ← Δ[ψ] 23: F ← [ ] 24: V ← [ ] 25: for each r ∈ R where r has head ψ_(f) do 26: let r be ψ_(f) := Op(ψ) 27: if exists v such that 

 Op 

 (P(I)) = v for all 28:  P ∈ topProgs and all inputs I in ϕ then 29: f ← 

 r 

 ( ) 30: F ← F · f 31: V ← V · v 32: return {Disj(topProgs, F, V)}

The configuration parameter C to the algorithm contains four domain-specific components used by the algorithm: DSL, InferSpec, Synth and Ranker. The DSL is the domain-specific language in which programs will be synthesized. InferSpec is a map from operator rules in the DSL to a specification inference function for the rule. Specification inference functions may be based on witness functions.

The specification inference function for an operator rule in the DSL is a function that computes specifications on the parameters of the operator given a specification on the operator itself. For a rule r in the DSL of the form ψ:=Op(ψ_(i), . . . , ψ_(n)) and an output specification ϕ on the output of this operator. InferSpec[r] is a function of the form F(ϕ, ψ_(i), [P₁, . . . , P_(i−1)]) that returns a specification ϕ_(i) for the ith parameter of the operator given the program expressions already computed for the first i−1 parameters.

For example, for the Concat(res, res) operator in the text DSL, assume there is a specification where the output should be s2 on an input s1. Then a specification inferred for the first parameter is that it should produce any prefix of s2. If such a program P producing a prefix s′ is learned, then a specification for the second parameter with respect to P: that the second parameter should produce any suffix s″ such that s2=s′±s″ may be inferred.

As another example of specification propagation, a specification ϕ for the substring operator Substr(p,p) produces output “bc” on input “abed”. In this case, the specification ϕ₁ inferred for the first parameter is that it should produce position 1 on the given input, while the specification ϕ₂ inferred for the second parameter is that it should produce position 3 on that input. As an example in the web DSL, a specification for the Select(fl, k) operator should output a node n. The specification inferred for the first parameter fl is that this should be any collection that contains n, while the specification for k depends on the first parameter and requires that k be the index of nin that collection.

Although specification inference functions may be provided for most operators in a DSL, for some DSL symbols, especially terminal symbols, domain-specific learning strategies may be used to infer the programs directly. This is the base case where specifications are no longer propagated downwards. For example, for an atomic regular expression token t in the text DSL, a specification may be propagated down from the position operator that the regex must have a match on input s that ends at position i in s. In this base case, this specification will not be propagated down further, but will simply check the possible atomic regexes in the DSL that satisfies this constraint and return those regexes. Such domain-specific learning strategies are provided in the Synth component of the configuration parameter C, which is a map from certain DSL symbols to functions for directly learning programs for that symbol from the given specification. For such a symbol ψ, Synth[ψ] is a function of the form F(ϕ) which returns a set of programs of type ψ that satisfy ϕ.

The final component of the configuration parameter C is the ranking function Ranker, which takes a set of programs and returns a list of top programs ordered according to some ranking criteria. For example, for the text DSL, Ranker may prefer “simpler” programs. In the web case, Ranker may be based on preferring the most specific programs for selecting nodes.

The synthesis algorithm is shown above in Table 7. The SynthProg(C, ϕ, ψ) returns a set of top-ranked programs of type ψ in the provided DSL that satisfy the given specification ϕ. To construct complete programs in the DSL, ψ is chosen to be the start symbol {tilde over (ψ)}_(st).

In a first phase, the algorithm computes the set of programs Progs that satisfy the specification (lines 3 to 17). If a specific synthesis function is already provided for this symbol in C then that synthesis function is used (line 5). Otherwise, synthesis is performed using the specification propagation approach. For each operator rule in the DSL with head ψ, possible programs are computed that use this operator at the top-level (lines 8 to 17). This may be done by building the lists of parameter instantiations of the operator (stored in the variable S) until instantiations for all parameters of the operator are determined.

For each parameter, a specification for that parameter is inferred using the instantiations of the previous parameters already computed (line 13). This specification is then used to synthesize programs for this parameter with a recursive call to the synthesis algorithm (line 14). These programs are used to grow the parameter instantiation list S (line 15). At line 17, all the possible programs are added using to the set Progs. In practice, various optimizations may be made over this general description. Optimizations may include caching the results of particular synthesis calls for a given specification which may often be repeated, clustering programs together that produce the same outputs, and setting recursion limits to bound the size of programs considered.

The next phase in the algorithm is to choose the top-ranked programs and to construct a disjunctive program as needed (lines 18 to 32). The top-ranked program is obtained from the set Progs using the ranking function. If the symbol ψ is not a disjunctive symbol in the DSL then the top-ranked set is returned (line 20). Otherwise, a disjunctive program is synthesized for the symbol ψ.

To synthesize the disjunctive program, the feature calculator symbol ψ_(f) is obtained. The feature calculator vector and the target feature values vector V are initialized (lines 22 to 24). The synthesizer then selects the features that will be included in the disjunctive program and to choose between different disjuncts. In an example, these features are selected as all the ones that yield the same value across all the training examples provided to the algorithm. A reason for this is to synthesize a disjunctive program that will prefer disjuncts whose result are most similar to the training examples.

For example, the text DSL includes the NotNull and NumChars features which indicate whether the output is null and the size of the output string respectively. Hence a program to address the text extraction task in Table 1 would use features: NotNull=True and NumChars=9. This is because those feature values are consistent across any example outputs in Table 1 that may be given to the synthesizer. Similarly, in the web case, the failure to return any result (or an empty result) is just a feature of the output that is handled in the same way: if all the example outputs given for a task are non-empty, then the synthesizer will include the NonEmpty feature in the disjunctive program with target value of True. Hence for each feature calculator rule in the DSL with head ψ_(f), the synthesizer checks if the top programs yield the same value for this feature in all the given example inputs (line 27). If such a consistent value v exists, then v is added to the target value vector V and the feature calculator function is added to the vector F. Finally, a single disjunctive program with the Disj operator using the vectors F and V, and the top-ranked programs as the disjuncts is returned.

The algorithm described above chooses the disjuncts in the final program using the top-ranked programs. In an example, the number of disjuncts may be 3, 5, 10, 20, etc. In the case of the text DSL where disjunctive synthesis was performed on the substring operator, the ranking used by the underlying Flash Fill system produced effective disjuncts. However, in the case of web extraction the existing synthesis systems did not provide adequate disjuncts for the filter operators, as these systems tend to favor the most specific condition possible or other heuristic techniques to choose the filtering condition, which did not work well in practice.

With the disjunctive approach, general conditions as possible disjuncts were considered to guard against overfitting. All possibilities, however, are unlikely to be used because, there may be an exponential number of possible conjunctive conditions c for the filter operator in the web DSL. Instead, in an example, a learning strategy for disjuncts that considers the maximal (the most specific) as well as a set of minimal (least restrictive) conjunctions that satisfy the specification may be used. This disjunct learning is implemented in the Synth[c](ϕ) function which synthesizes conditions for the filter operator.

The specification ϕ given to this function specifies that the computed condition expression P must hold for a subset N′ of the input node set N. In an example, the learning function first computes all the atomic predicates A1, . . . , An of symbol c that satisfy the specification. The top-ranked disjunct considered is the most specific condition P1=A1 Λ. . . Λ An. The remaining disjuncts may then be computed as the smallest conjunctions that produce the same filtered set of nodes as P1 on the input set. This makes the disjuncts semantically equivalent programs over the given input. As this computation of minimals is equivalent to the minimal set cover problem which is NP-complete, a greedy approximation algorithm may be used to compute the minimals efficiently. Every atomic predicate Ai is ensured to be included in some minimal, in order to produce an effective set of disjuncts that cover all predicates in the disjunctive program.

To test the described DSLs and disjunctive program synthesis for both the text and web extraction domains Microsoft@ PROSE® framework was used for program synthesis. To text synthesis email extraction tasks were considered. Users often get emails regularly from the same provider such as flight itineraries, hotel bookings or purchase receipts, and user would like a PBE feature that allows users to create work flows for extracting important content from email. For example, useful information may be extracted when an email arrives. In an example, users may give examples to the PBE system by highlighting important fields in existing emails. However, in this scenario the web extraction DSL alone does not suffice, as many of the provided benchmarks include substring extractions from nodes in the HTML. The DSL

which incorporates both the web and text DSLs may be used, so the extraction program first selects a node and then performs a substring extraction on its text content.

To test performance, forty-seven extraction tasks from eight different providers were used. Thirty-four tasks required substring extractions on the node content rather than just node selections. For each extraction task, there were one, two, three, five, ten, etc. test instances of an input and the desired output. In each instance, the input was an email and the output was a text string of the field to be extracted, e.g., the flight number from a flight confirmation email, etc.

An important consideration for a synthesized program is for the system to learn robust programs that do not easily fail on new inputs. To measure robustness the minimum number of examples required to learn a correct a program for a given task was used. More precisely, the minimum number of examples is the minimum number of input-output instances that were required as examples to be given to the system such that the program it synthesized succeeded on all the remaining instances.

The disjunctive learning system was compared against a baseline system that did not include any disjunctive operators in the same DSL. FIG. 1 shows the comparison of the minimum number of examples required by the disjunctive approach 110 and the baseline 120. In summary, the proportion of tasks for which a correct program was synthesized from one example increased from 59.6% to 93.6% with the disjunctive approach.

These results show the minimum number of examples required to learn a correct program, rather than the number of examples a user may provide in practice, which could be many more. This is because a user does not know which examples will be useful for the system (e.g., representative samples covering all “corner cases”) and while they may make the effort to give many more examples, they may only encounter the relevant or useful examples when the system fails to work on some future email. This uncertainty of not knowing which examples to give makes the difference between requiring one or more examples important for the user experience and product quality.

In terms of performance, there was an average of 2.9× slowdown in the disjunctive case, which is expected since disjunctive programs perform more computations as they consider multiple alternative branches. However, most test instances in the disjunctive case completed in under half a second and all completed in under two seconds.

FIG. 2 is a flow diagram of a process for synthesizing a disjunctive program in accordance with respective examples. In an example, the disjunctive program attempts to determine an intent of the user from a limited number of input/output examples. The number of input/output examples may be a single input/output example. The disjunctive program may then be used on different input to generate output in a form intended by the user. Examples of synthesized programs include extracting data from an email, formatting data, etc.

At 210, a domain specific language is received. The domain specific language includes at least one symbol that is specified as a disjunctive symbol. The disjunctive symbol indicates that instances of this symbol in a program and/or sub-program may contain more than one logics that are selected at runtime. At 220, an input/output example is received. More than one input/output example may be received. In one example, a single input/output example is received. The input may be an email, a web page, text, etc. The output may be text.

Using the domain specific language and the input/output example, a program is synthesized. The synthesis includes handling instances of disjunctive symbols. At 230, as part of synthesizing the program, two or more sub-programs for an instance of a disjunctive symbol are synthesized. The sub-program may be part of the final program. In addition, the entire program may be a disjunctive program. At 240, for an instance of a disjunctive symbol, a feature calculator is determined. In an example, there are multiple possible feature calculators. One way to determine the feature calculators for a specific disjunctive instance is to include all of the feature calculators. When there are multiple input/output examples, the set of feature calculators may include the feature calculators that have a consistent result across all input/output examples. At 250, a set of feature values are determined. The feature values represent the features of a valid output. In an example, the output of the selected feature calculators is used as the set of feature values. At 260, once the synthesis is completed the program is returned. The returned program includes the sub-programs from 230, the set of feature calculators from 240, and the set of feature values from 250.

After the program is returned, the program may be executed on new input that is not part of the provided input/output examples from 220. Accordingly, the new input cannot have been used during synthesis of the program. Unlike traditional PBE systems, the program from 260 uses the different sub-programs from 230 to be more flexible in how new input is handled. Accordingly, the program is able to be more robust in that different sub-programs may be run on different data to produce more accurate output. In addition, the feature calculators and feature values help ensure that the output has features consistent or close to the feature values.

Once the new input is received, the program is executed. Execution of the program is different from traditional PBE generated programs since a specific sub-program for each disjunction symbol instance is selected. When a disjunctive instance is executed, each of the sub-programs may be executed on the new input. The output from each of the sub-programs may then be passed to each of the feature calculators associated with that instance. The output from the feature calculators may then be compared with the feature values. In an example, the sub-program that created the output whose feature calculator values are closest to the feature values from 250 is selected.

FIG. 3 is an example computing device that can be used in conjunction with the technologies described herein. In alternative embodiments, the computing device 300 may operate as a standalone device or may be connected (e.g., networked) to other computing devices. In a networked deployment, the computing device 300 may operate in the capacity of a server communication device, a client communication device, or both in server-client network environments. In an example, the computing device 300 may act as a peer computing device in peer-to-peer (P2P) (or other distributed) network environment. The computing device 300 may be a personal computer (PC), a tablet PC, a set top box (STB), a personal digital assistant (PDA), a mobile telephone, a smart phone, a web appliance, a network router, switch or bridge, or any computing device capable of executing instructions (sequential or otherwise) that specify actions to be taken by that computing device. Further, while only a single computing device is illustrated, the term “computing device” shall also be taken to include any collection of computing devices that individually or jointly execute a set (or multiple sets) of instructions to perform any one or more of the methodologies discussed herein, such as cloud computing, software as a service (SaaS), other computer cluster configurations. Computing device may be an implementation of device 110, 120, 130, and may implement the profile store 140, and perform the method of FIG. 2.

Computing device 300 may include a hardware processor 302 (e.g., a central processing unit (CPU), a graphics processing unit (GPU), a hardware processor core, or any combination thereof), a main memory 304 and a static memory 306, some or all of which may communicate with each other via a link (e.g., bus) 308. The computing device 300 may further include a display unit 310, an input device 312 (e.g., a keyboard), and a user interface (UI) navigation device 314 (e.g., a mouse). In an example, the display unit 310, input device 312, and UI navigation device 314 may be a touch screen display. In an example, the input device 312 may include a touchscreen, a microphone, a camera (e.g., a panoramic or high-resolution camera), physical keyboard, trackball, or other input devices.

The computing device 300 may additionally include a storage device (e.g., drive unit) 316, a signal generation device 318 (e.g., a speaker, a projection device, or any other type of information output device), a network interface device 320, and one or more sensors 321, such as a global positioning system (GPS) sensor, compass, accelerometer, motion detector, or other sensor. The computing device 300 may include an input/output controller 328, such as a serial (e.g., universal serial bus (USB), parallel, or other wired or wireless (e.g., infrared (IR), near field communication (NFC), etc.) connection to communicate or control one or more peripheral devices (e.g., a printer, card reader, etc. via one or more input/output ports.

The storage device 316 may include a computing-readable (or machine-readable) storage media 322, on which is stored one or more sets of data structures or instructions 324 (e.g., software) embodying or utilized by any one or more of the techniques or functions described herein. In an example, at least a portion of the software may include an operating system and/or one or more applications (or apps) implementing one or more of the functionalities described herein. The instructions 324 may also reside, completely or at least partially, within the main memory 304, within the static memory 306, and/or within the hardware processor 302 during execution thereof by the computing device 300. In an example, one or any combination of the hardware processor 302, the main memory 304, the static memory 306, or the storage device 316 may constitute computing device (or machine) readable media.

While the computer-readable storage media 322 is illustrated as a single medium, a “computer-readable storage media” or “machine-readable storage media” may include a single medium or multiple media (e.g., a centralized or distributed database, and/or associated caches and servers) configured to store the one or more instructions 324.

In an example, a computer-readable storage media or machine-readable storage media may include any medium that is capable of storing, encoding, or carrying instructions for execution by the computing device 300 and that cause the computing device 300 to perform any one or more of the techniques of the present disclosure, or that is capable of storing, encoding or carrying data structures used by or associated with such instructions. Non-limiting computer-readable storage media examples may include solid-state memories, and optical and magnetic media. Specific examples of computer-readable storage media may include: non-volatile memory, such as semiconductor memory devices (e.g., Electrically Programmable Read-Only Memory (EPROM), Electrically Erasable Programmable Read-Only Memory (EEPROM)) and flash memory devices; magnetic disks, such as internal hard disks and removable disks; magneto-optical disks; Random Access Memory (RAM); and optical media disks. The computer-readable storage media is non-transitory in that the storage media does not consist of transitory propagating signals.

The instructions 324 may further be transmitted or received over a communications network 326 using a transmission medium via the network interface device 320 utilizing any one of a number of transfer protocols (e.g., frame relay, internee protocol (IP), transmission control protocol (TCP), user datagrarn protocol (UDP), hypertext transfer protocol (HTTP), etc.). Example communication networks may include a local area network (LAN), a wide area network (WAN), a packet data network (e.g., the Internet), mobile telephone networks (e.g., cellular networks), Plain Old Telephone (POTS) networks, and wireless data networks (e.g., Institute of Electrical and Electronics Engineers (IEEE) 802.3 family of standards known as Wi-Fi®, IEEE 802.16 family of standards known as WiMax®), IEEE 802.15.4 family of standards, a Long Term Evolution (LTE) family of standards, a Universal Mobile Telecommunications System (UMTS) family of standards, peer-to-peer (P2P) networks, among others. The network interface device 320 may use the transfer protocols to transmit data using transitory propagating signals.

In an example, the network interface device 320 may include one or more physical jacks (e.g., Ethernet, coaxial, or phone jacks) or one or more antennas to connect to the communications network 326. In an example, the network interface device 320 may include one or more wireless moderns, such as a Bluetooth modem, a Wi-Fi modem or one or more modems or transceivers operating under any of the communication standards mentioned herein. In an example, the network interface device 320 may include a plurality of antennas to wirelessly communicate using at least one of single-input multiple-output (SIMO), multiple-input multiple-output (MIMO), or multiple-input single-output (MISO) techniques. In some examples, the network interface device 320 may wirelessly communicate using Multiple User MIMO techniques. In an example, a transmission medium may include any intangible medium that is capable of storing, encoding or carrying instructions for execution by the computing device 300, and includes digital or analog communications signals or like communication media to facilitate communication of such software.

Any of the computer-executable instructions for implementing the disclosed techniques as well as any data created and used during implementation of the disclosed embodiments can be stored on one or more computer-readable storage media. The computer-executable instructions can be part of, for example, a dedicated software application or a software application that is accessed or downloaded via a web browser or other software application (such as a remote computing application). Such software can be executed, for example, on a single local computer (e.g., any suitable commercially available computer) or in a network environment (e.g., via the Internet, a wide-area network, a local-area network, a client-server network (such as a cloud computing network), or other such network) using one or more network computers.

The above description is intended to be illustrative, and not restrictive. For example, the above-described examples (or one or more aspects thereof) may be used in combination with others. Other embodiments may be used, such as by one of ordinary skill in the art upon reviewing the above description. Further, the following claims are hereby incorporated into the Detailed Description, with a claim standing on its own as a separate embodiment. The scope of the embodiments disclosed herein is to be determined with reference to the appended claims, along with the full scope of equivalents to which such claims are entitled. 

1. A method for synthesizing a program for a task, the method comprising operations performed using an electronic processor, the operations comprising: receiving a domain specific language comprising a disjunctive symbol; receiving a first input/output example for the task; synthesizing a program for the task for execution on an electronic processor based on the first input/output example and the domain specific language, wherein the synthesizing comprises: synthesizing a plurality of sub-programs for an instance of the disjunctive symbol based on the domain specific language; determining a set of feature calculators based on the plurality of sub-programs and the first input/output example for the instance of the disjunctive symbol; and determining a set of target feature values based on the plurality of sub-programs and the first input/output example for the instance of the disjunctive symbol; and returning the program for the task comprising the plurality of sub-programs, the set of feature calculators, and the set of target feature values.
 2. The method of claim 1, further comprising ordering the sub-programs.
 3. The method of claim 2, further comprising executing the program.
 4. The method of claim 3, wherein executing the program comprises: receiving a second input/output example different from the first input/output example; for each of the sub-programs: executing the sub-program on the second input/output example to generate a disjunct output; executing the set of feature calculators on the disjunct output to generate feature outputs; and comparing the feature outputs to the set of target feature values; and selecting the disjunct output from the plurality of sub-programs based on the comparing the feature outputs to the set of target feature values.
 4. The method of claim 2, wherein executing the program comprises: receiving a second input/output example different from the first input/output example; and selecting output from a sub-program whose output satisfies a threshold, wherein the sub-programs are executed based on the ordering.
 6. The method of claim 1, wherein the determining a set of feature calculators comprises determining a feature calculator that has a consistent result across all of the plurality of sub-programs and the input/output example.
 7. The method of claim 6, wherein the determining a set of target feature values comprises adding the consistent result to the set of target feature values.
 8. The method of claim 1, wherein the set of feature calculators comprises one of a not null feature calculator, a number of characters feature calculator, a number of non-white-space characters feature calculator, and a number of special characters feature calculator.
 9. A system for synthesizing a program for a task comprising: one or more electronic processors, the one or more electronic processors configured to: receive a domain specific language comprising a disjunctive symbol; receive a first input/output example for the task; synthesize a program for the task based on the first input/output example and the domain specific language, wherein the synthesizing comprises: synthesize a plurality of sub-programs for an instance of the disjunctive symbol based on the domain specific language; determine a set of feature calculators based on the plurality of sub-programs and the first input/output example for the instance of the disjunctive symbol; and determine a set of target feature values based on the plurality of sub-programs and the first input/output example for the instance of the disjunctive symbol; and return the program for the task comprising the plurality of sub-programs, the set of feature calculators, and the set of target feature values.
 10. The system of claim 9, wherein the one or more processors are further configured to order the sub-programs.
 11. The system of claim 10, wherein the one or more processors are further configured to execute the program.
 12. The system of claim 11, wherein to execute the program the one or more processors are configured to: receive a second input/output example different from the first input/output example; for each of the sub-programs: execute the sub-program on the second input/output example to generate a disjunct output; execute the set of feature calculators on the disjunct output to generate feature outputs; and compare the feature outputs to the set of target feature values; and select the disjunct output from the plurality of sub-programs based on the comparison of the feature outputs to the set of target feature values.
 13. The system of claim 9, wherein to determine a set of feature calculators the one or more processors are configured to determine a feature calculator that has a consistent result across all of the plurality of sub-programs and the input/output example.
 14. The system of claim 13, wherein to determine a set of target feature values the one or more processors are further configured to add the consistent result to the set of target feature values.
 15. The system of claim 9, wherein the set of feature calculators comprises one of a not null feature calculator, a number of characters feature calculator, a number of non-white-space characters feature calculator, and a number of special characters feature calculator.
 16. A computer-readable storage media storing computer-executable instructions for synthesizing a task for a program, the stored instructions comprising: instructions to receive a domain specific language comprising a disjunctive symbol; instructions to receive a first input/output example for the task; instructions to synthesize a program fur the task based on the first input/output example and the domain specific language, wherein the synthesizing comprises: instructions to synthesize a plurality of sub-programs for an instance of the disjunctive symbol based on the domain specific language; instructions to determine a set of feature calculators based on the plurality of sub-programs and the first input/output example for the instance of the disjunctive symbol; and instructions to determine a set of target feature values based on the plurality of sub-programs and the first input/output example for the instance of the disjunctive symbol; and instructions to return the program for the task comprising the plurality of sub-programs, the set of feature calculators, and the set of target feature values.
 17. The computer-readable storage media of claim 16, the instructions further comprise instructions to order the sub-programs.
 18. The computer-readable storage media of claim 17, wherein the instructions further comprise instructions to execute the program.
 19. The computer-readable storage media of claim 18, wherein the instructions to execute the program further comprise instructions: instructions to receive a second input/output example different from the first input/output example; for each of the sub-programs: instructions to execute the sub-program on the second input/output example to generate a disjunct output; instructions to execute the set of feature calculators on the disjunct output to generate feature outputs; and instructions to compare the feature outputs to the set of target feature values; and instructions to select the disjunct output from the plurality of sub-programs based on the comparison of the feature outputs to the set of target feature values.
 20. The computer-readable storage media of claim 16, wherein the instructions to determine a set of feature calculators the instructions further comprise instructions to determine a feature calculator that has a consistent result across all of the plurality of sub-programs and the input/output example. 